#pragma once
#include "resource.h"       // main symbols
#include "atlbase.h"
#include "MMC.h"
#include "atlsnap.h"
#include "UserComponent.h"
#include "MMC_2_0_i.h"
#include "Server.h"
#include "ActiveX.h"

// CSnapInAbout

class ATL_NO_VTABLE CSnapInAbout :public ISnapinAbout,
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CSnapInAbout, &CLSID_SnapInAbout>
{
	HBITMAP				m_hSmallImage;
    HBITMAP				m_hLargeImage;
    HBITMAP				m_hSmallImageOpen;
	HICON				m_hAppIcon;
public:
	CSnapInAbout()
	{
		m_hSmallImage = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_SIMPLE_16), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT);
		m_hLargeImage = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_SIMPLE_32), IMAGE_BITMAP, 32, 32, LR_LOADTRANSPARENT);
		m_hSmallImageOpen = (HBITMAP)LoadImage(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDB_SMOPEN), IMAGE_BITMAP, 16, 16, LR_LOADTRANSPARENT);
		m_hAppIcon = LoadIcon(_Module.GetModuleInstance(), MAKEINTRESOURCE(IDI_APPICON));
	}
	~CSnapInAbout()
	{
		::DeleteObject(m_hSmallImage);
		::DeleteObject(m_hLargeImage);
		::DeleteObject(m_hSmallImageOpen);
		::DestroyIcon(m_hAppIcon);
	}

	DECLARE_REGISTRY(CSnapInAbout, _T("SnapInAbout.1"), _T("SnapInAbout.1"), IDS_SIMPLE_DESC, THREADFLAGS_BOTH);
//	DECLARE_REGISTRY_RESOURCEID(IDR_SNAPINABOUT)
	BEGIN_COM_MAP(CSnapInAbout)
		COM_INTERFACE_ENTRY(ISnapinAbout)
	END_COM_MAP()

	STDMETHOD(GetSnapinDescription)(LPOLESTR *lpDescription)
	{
		USES_CONVERSION;
		TCHAR szBuf[256];
		if (::LoadString(_Module.GetResourceInstance(), IDS_SIMPLE_DESC, szBuf, 256) == 0)
			return E_FAIL;

		*lpDescription = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
		if (*lpDescription == NULL)
			return E_OUTOFMEMORY;

		ocscpy(*lpDescription, T2OLE(szBuf));

		return S_OK;
	}

	STDMETHOD(GetProvider)(LPOLESTR *lpName)
	{
		USES_CONVERSION;
		TCHAR szBuf[256];
		if (::LoadString(_Module.GetResourceInstance(), IDS_SIMPLE_PROVIDER, szBuf, 256) == 0)
			return E_FAIL;

		*lpName = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
		if (*lpName == NULL)
			return E_OUTOFMEMORY;

		ocscpy(*lpName, T2OLE(szBuf));

		return S_OK;
	}

	STDMETHOD(GetSnapinVersion)(LPOLESTR *lpVersion)
	{
		USES_CONVERSION;
		TCHAR szBuf[256];
		if (::LoadString(_Module.GetResourceInstance(), IDS_SIMPLE_VERSION, szBuf, 256) == 0)
			return E_FAIL;

		*lpVersion = (LPOLESTR)CoTaskMemAlloc((lstrlen(szBuf) + 1) * sizeof(OLECHAR));
		if (*lpVersion == NULL)
			return E_OUTOFMEMORY;

		ocscpy(*lpVersion, T2OLE(szBuf));

		return S_OK;
	}

	STDMETHOD(GetSnapinImage)(HICON *hAppIcon)
	{
		*hAppIcon = m_hAppIcon;
		return S_OK;
	}

	STDMETHOD(GetStaticFolderImage)(HBITMAP *hSmallImage,
		HBITMAP *hSmallImageOpen,
		HBITMAP *hLargeImage,
		COLORREF *cMask)
	{
		*hSmallImage = m_hSmallImage;
		*hSmallImageOpen = m_hSmallImageOpen;
		*hLargeImage = m_hLargeImage;
		*cMask = RGB(0, 128, 128);
		if (*hSmallImage == NULL || *hLargeImage == NULL || 
         *hSmallImageOpen == NULL)
			return E_FAIL;
		else
	        return S_OK;
	}

//public:
//	CSnapInAbout()
//	{
//	}
//
//DECLARE_REGISTRY_RESOURCEID(IDR_SNAPINABOUT)
//
//
//BEGIN_COM_MAP(CSnapInAbout)
//	COM_INTERFACE_ENTRY(ISnapInAbout)
//	COM_INTERFACE_ENTRY(IDispatch)
//END_COM_MAP()
//
//
//
//	DECLARE_PROTECT_FINAL_CONSTRUCT()
//
//	HRESULT FinalConstruct()
//	{
//		return S_OK;
//	}
//
//	void FinalRelease()
//	{
//	}
//
//public:

};

OBJECT_ENTRY_AUTO(__uuidof(SnapInAbout), CSnapInAbout)
